import { request } from '../request';

/** 曲线配置相关API */

// 曲线配置接口类型定义
export interface CurveConfig {
  id?: number;
  currency: string;
  type: string;
  fxContract: string;
  idx: string;
  typology: string;
  desk: string;
  generator: string;
  curveType: string;
  curveName: string;
  description?: string;
  configParams?: string;
  status: number;
  createTime?: string;
  updateTime?: string;
}

export interface CurveConfigSearchParams {
  curveName?: string;
  curveType?: string;
  currency?: string;
  current?: number;
  size?: number;
}

export interface CurveConfigListResponse {
  records: CurveConfig[];
  total: number;
  current: number;
  size: number;
}

/** 获取曲线配置列表 */
export function fetchCurveConfigList(params?: CurveConfigSearchParams) {
  return request<CurveConfigListResponse>({
    url: '/api/rate-assignment/list',
    method: 'get',
    params
  });
}
/** 获取曲线配置ID列表 */
export function fetchCurveConfigIdList(params?: CurveConfigSearchParams) {
  return request<CurveConfigListResponse>({
    url: '/api/rate-assignment/list-datasetId',
    method: 'get',
    params
  });
}
/** 根据ID获取曲线配置详情 */
export function fetchCurveConfigById(id: number) {
  return request<CurveConfig>({
    url: `/api/rate-assignment/id/${id}`,
    method: 'get'
  });
}

/** 创建曲线配置 */
export function createCurveConfig(data: Omit<CurveConfig, 'id' | 'createTime' | 'updateTime'>) {
  return request<CurveConfig>({
    url: '/api/rate-assignment/create',
    method: 'post',
    data
  });
}

/** 更新曲线配置 */
export function updateCurveConfig(id: number, data: Partial<CurveConfig>) {
  return request<CurveConfig>({
    url: `/api/rate-assignment/${id}`,
    method: 'put',
    data
  });
}

/** 删除曲线配置：根据ID删除一条曲线映射记录 */
export function deleteCurveConfig(id: number) {
  return request<string>({
    url: `/api/rate-assignment/${id}`,
    method: 'delete'
  });
}

// 利率分配相关API（连接到RateAssignmentController）
export interface RateAssignment {
  id?: number;
  currency: string;
  typology: string;
  userId: string;
  groupId: string;
  rateValue?: number;
  effectiveDate?: string;
  expiryDate?: string;
  status?: number;
}

/** 查找利率分配 */
export function findRateAssignment(params: { currency: string; typology: string; userId: string; groupId: string }) {
  return request<RateAssignment>({ url: '/api/rate-assignment/find', method: 'get', params });
}

/** 曲线定义相关类型 */
export interface CurveDefinitionDTO {
  id: number;
  curveName: string;
  currency: string;
  curveType: string;
  description?: string;
  status: number;
}

/** 获取所有曲线定义列表 */
export function fetchCurveDefinitionList() {
  return request<CurveDefinitionDTO[]>({
    url: '/api/curve/definition',
    method: 'get'
  });
}

/** 根据货币对获取曲线定义列表 */
export function fetchCurveDefinitionsByCurrency(currencyPair: string) {
  return request<CurveDefinitionDTO[]>({
    url: `/api/curve/definition/currency/${currencyPair}`,
    method: 'get'
  });
}
